import SwiftUI

struct AnimatableProperties_Trim : View {
    @State var progress: Double = 0
    
    var body: some View {
        VStack(spacing: 30) {
            Text("Animatable Properties")
                .font(.largeTitle)
            
            Text("Trim")
                .font(.title)
            
            Text(".....")
            
            makeDemoView()
            
            Spacer()
            
            Button(action: {
                progress += 0.7
                
                if progress >= 1.0 {
                    progress = 0
                }
            }, label: {
                Text("Trim")
                    .font(.title)
                    .padding(.bottom, 50)
            })
        }
    }
    
    func makeDemoView() -> some View {
        // Circle
        ZStack {
            Circle()
                .trim(from: 0, to: progress)
                .stroke(Color.blue, style: StrokeStyle(lineWidth: 40, lineCap: .round))
                .padding(.horizontal, 50)
            
            Text("\(progress * 100) %")
                .font(.title)
                .foregroundColor(.yellow)            
        }
        .animation(.linear, value: progress)
    }
}
